// Doctrine CC
// Holy/Prot/Ret
// by fiftypence
//
// Please note if you wish to reuse code found in any function
// within the Doctrine namespace, credit should be given to
// both the CC and CC author in your release thread.
// It is only fair.
//
// Thank you.

using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Drawing;

using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.Combat;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

using Doctrine.Talents;

using CommonBehaviors.Actions;
using TreeSharp;
using Action = TreeSharp.Action;

namespace Doctrine
{
    partial class Paladin : CombatRoutine
    {
        public Version curVersion = new Version(1, 0, 0);
            
        public override string Name { get { return "Doctrine v" + curVersion; } }
        public override WoWClass Class { get { return WoWClass.Paladin; } }

        private static LocalPlayer Me { get { return ObjectManager.Me; } }
        private readonly SpecManager Talent = new SpecManager();

        public override void Initialize()
        {
            Logging.Write(Color.Orange, "");
            Logging.Write(Color.Orange, Name + " is now operational.");
            Logging.Write(Color.Orange, "");
            Logging.Write(Color.Orange, "Greetings {0}!", Me.Name);
            Logging.Write(Color.Orange, "You are a level {0} {1} {2} {3}.", Me.Level, Me.Race, Talent.Spec, Me.Class);
            Logging.Write(Color.Orange, "");
            Logging.Write(Color.Orange, "Building Behavior Tree.");
        }

        #region Composite declarations

        /* Composites seem to have the following priority order: 
         *    Rest
         *    PreCombatBuff
         *    Pull
         *    Heal
         *    CombatBuff
         *    Combat
         *    
         * This implies that each composite we override is equivalent to 
         * a node in a PrioritySelector.
         * 
         * e.g.: if Rest returns RunStatus.Success to the tree-walker, no
         * other overrides are visited. 
         * 
         * If the player is in combat, only Heal, CombatBuff, and Combat
         * are visited by the tree-walker.
         */

        private Composite _CombatBehavior;
        private Composite _PullBehavior;
        private Composite _MoveToTargetBehavior;

        private Composite _CombatBuffBehavior;
        private Composite _PreCombatBuffBehavior;

        private Composite _RestBehavior;
        private Composite _HealBehavior;

        public override Composite CombatBehavior
        {
            get
            {
                if (_CombatBehavior == null)
                {
                    switch (Talent.Spec)
                    {
                        case SpecManager.SpecList.None:

                            _CombatBehavior = BuildLowLevelCombatBehavior();
                            Logging.Write(Color.Orange, "  Low level combat behavior built");
                            break;

                        case SpecManager.SpecList.Holy:

                            _CombatBehavior = BuildHolyCombatBehavior();
                            Logging.Write(Color.Orange, "  Holy combat behavior built");
                            break;

                        case SpecManager.SpecList.Protection:

                            _CombatBehavior = BuildProtCombatBehavior();
                            Logging.Write(Color.Orange, "  Protection combat behavior built");
                            break;

                        case SpecManager.SpecList.Retribution:

                            _CombatBehavior = BuildRetCombatBehavior();
                            Logging.Write(Color.Orange, "  Retribution combat behavior built");
                            break;
                    }
                }

                return _CombatBehavior;
            }
        }

        public override Composite PullBehavior
        {
            get
            {
                if (_PullBehavior == null)
                {
                    Logging.Write(Color.Orange, "  Pull behavior built");

                    _PullBehavior = BuildPullBehavior();
                }

                return _PullBehavior;
            }
        }

        public override Composite MoveToTargetBehavior
        {
            get
            {
                if (_MoveToTargetBehavior == null)
                {
                    Logging.Write(Color.Orange, "  MoveToTarget behavior built");

                    _MoveToTargetBehavior = BuildMoveToTargetBehavior();
                }

                return _MoveToTargetBehavior;
            }
        }

        public override Composite CombatBuffBehavior
        {
            get
            {
                if (_CombatBuffBehavior == null)
                {
                    switch (Talent.Spec)
                    {
                        case SpecManager.SpecList.None:

                            _CombatBuffBehavior = BuildLowLevelCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Low level CombatBuff behavior built");
                            break;

                        case SpecManager.SpecList.Holy:

                            _CombatBuffBehavior = BuildHolyCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Holy CombatBuff behavior built");
                            break;

                        case SpecManager.SpecList.Protection:

                            _CombatBuffBehavior = BuildProtCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Protection CombatBuff behavior built");
                            break;

                        case SpecManager.SpecList.Retribution:

                            _CombatBuffBehavior = BuildRetCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Retribution CombatBuff behavior built");
                            break;
                    }
                }

                return _CombatBuffBehavior;
            }
        }

        public override Composite PreCombatBuffBehavior
        {
            get
            {
                if (_PreCombatBuffBehavior == null)
                {
                    switch (Talent.Spec)
                    {
                        case SpecManager.SpecList.None:

                            _PreCombatBuffBehavior = BuildLowLevelPreCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Low level PreCombatBuff behavior built");
                            break;

                        case SpecManager.SpecList.Holy:

                            _PreCombatBuffBehavior = BuildHolyPreCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Holy PreCombatBuff behavior built");
                            break;

                        case SpecManager.SpecList.Protection:

                            _PreCombatBuffBehavior = BuildProtPreCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Protection PreCombatBuff behavior built");
                            break;

                        case SpecManager.SpecList.Retribution:

                            _PreCombatBuffBehavior = BuildRetPreCombatBuffBehavior();
                            Logging.Write(Color.Orange, "  Retribution PreCombatBuff behavior built");
                            break;
                    }
                }

                return _PreCombatBuffBehavior;
            }
        }

        public override Composite RestBehavior
        {
            get
            {
                if (_RestBehavior == null)
                {
                    Logging.Write(Color.Orange, "  Rest behavior built");

                    _RestBehavior = BuildRestBehavior();
                }

                return _RestBehavior;
            }
        }

        public override Composite HealBehavior
        {
            get
            {
                if (_HealBehavior == null)
                {
                    Logging.Write(Color.Orange, "  Heal behavior built");

                    _HealBehavior = BuildHealBehavior();
                }

                return _HealBehavior;
            }
        }

        #endregion
    }
}